﻿namespace Liu_Project.Utils
{
    public static class CommonFunction
    {
        /// <summary>
        /// 返回：{"Code":"Fail" ,Error:"错误信息"}
        /// 格式错误信息
        /// </summary>
        /// <param name="Message">错误信息</param>
        /// <returns></returns>
        public static string ErrorJson(string Message, int code = 0)
        {
            System.Collections.Hashtable hash = new System.Collections.Hashtable();
            hash["IsSuccess"] = false;
            hash["code"] = code;
            hash["msg"] = Message;
            hash["data"] = "";
            return Newtonsoft.Json.JsonConvert.SerializeObject(hash);
        }

        /// <summary>
        /// 返回：{"Code":"success" ,Data:"成功返回值"}
        /// 格式成功信息
        /// </summary>
        /// <returns></returns>
        public static string SuccessJson()
        {
            return SuccessJson("ok");
        }

        /// <summary>
        /// 返回：{"Code":"success" ,Data:"成功返回值"}
        /// 格式成功信息
        /// </summary>
        /// <param name="data">成功返回值</param>
        /// <returns></returns>
        public static string SuccessJson(object data)
        {
            System.Collections.Hashtable hash = new System.Collections.Hashtable();
            hash["IsSuccess"] = true;
            hash["code"] = 1;
            hash["msg"] = "";
            hash["data"] = data;
            return Newtonsoft.Json.JsonConvert.SerializeObject(hash);
        }

        /// <summary>
        /// 返回：{"Code":"success" ,Data:"成功返回值"}
        /// 格式成功信息
        /// </summary>
        /// <param name="data">成功返回值</param>
        /// <returns></returns>
        public static string SuccessJson(object data, object total, string msg = "")
        {
            System.Collections.Hashtable hash = new System.Collections.Hashtable();
            hash["IsSuccess"] = true;
            hash["code"] = 1;
            hash["msg"] = msg;
            hash["data"] = data;
            hash["total"] = total;
            return Newtonsoft.Json.JsonConvert.SerializeObject(hash);
        }

    }
}
